import { defineStore } from "pinia";

interface ObjectList {
  [key: string]: string[];
}

export const usePermissStore = defineStore("permiss", {
  state: () => {
    const defaultList: ObjectList = {
      admin: ["0", "1", "2", "3", "4", "11", "12", "21", "22", "31"],
      user: ["0", "1", "2", "3", "4", "11", "12", "21", "22", "31"]
    };
    const role = localStorage.getItem("role");
    return {
      key: (role === "admin" ? defaultList.admin : defaultList.user) as string[],
      defaultList
    };
  },
  actions: {
    handleSet(val: string[]) {
      this.key = val;
    },
    getUserRole(): string {
      return localStorage.getItem("role") || "user";
    }
  }
});
